#pragma once
#include "util/noncopyable.h"
#include "base/config.h"

#include <vector>
#include <atomic>

#include <sys/epoll.h>
namespace net_tools::base
{
  class Channel;
  class Channelpool;
  class Epoll : util::noncopyable
  {
  public:
    Epoll(int size = _C::CHANNEL_DEFAULT_SIZE, std::atomic<bool> *wakeup = nullptr);
    ~Epoll(){};
    void Epoll_wait(int time_out);
    void Add_event(Channel *channel_);
    void Mod_event(Channel *channel_);
    void Del_event(Channel *channel_);
    Channel *Get_free_channel(int fd);
    void Free_channel(Channel *channel);

  private:
    std::vector<epoll_event> epoll_event_; //ready event_;
    Channelpool *channelpool_;             //one thread one pool;
    int epollid_;
    std::atomic<bool> *wakeup_;
    int max_event_number_;
    int last_time_triggered_;
  };

} // namespace net_tools::base